package com.gy.education.mine;

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.gy.education.BaseActivity;
import com.gy.education.R;

/**
 * Created by 高岳 on 2016/7/14.
 * Describe:认证
 */
public class IdentifyActivity extends BaseActivity{

    private TakePhotoFramgment takePhotoFramgment;
    private ImageView imgTake,imgBg;
    private Matrix matrix = new Matrix();
    private int position;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_identify);
        setTitleMsg("认证");
        imgTake = (ImageView) findViewById(R.id.activity_identify_img);
        imgBg = (ImageView) findViewById(R.id.activity_identify_img_bg);
    }

    @Override
    protected void initData() {
        position = getIntent().getIntExtra("position",0);
        takePhotoFramgment = new TakePhotoFramgment();
        Bundle takePhotoFramgmentBundle = new Bundle();
        takePhotoFramgmentBundle.putInt("position", position);
        takePhotoFramgment.setArguments(takePhotoFramgmentBundle);
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.activity_identify_frame, takePhotoFramgment, "TAKE").commit();
    }

    @Override
    protected void setListener() {
        super.setListener();
        imgTake.setOnClickListener(this);
    }

    @Override
    protected void fillData() {
        super.fillData();

        if(position == 101){
            imgBg.setVisibility(View.VISIBLE);
        } else {
            imgBg.setVisibility(View.GONE);
        }

        Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.icon_identity_front)).getBitmap();
        // 设置旋转角度
        matrix.setRotate(90);
        // 重新绘制Bitmap
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),bitmap.getHeight(), matrix, true);
        imgBg.setImageBitmap(bitmap);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.activity_identify_img:
                if (getSupportFragmentManager().findFragmentByTag("TAKE") != null) {
                    takePhotoFramgment.takePic();
                }
                break;
        }
    }
}
